package edu.sctu.zhangwang.day201506;

import java.io.*;

/**
 * Created by user10 on 2015/6/14.
 */
public class IoUtil {

    public void input(){
        int count ;
        int a = 0;

        try {
            FileInputStream is = new FileInputStream("D://dow.txt");
            int n = 1024;
            byte bytes[] = new byte[n];
            try {
                while ((count =is.read(bytes)) != -1){
                    a += count;
                    System.out.println();
                }
                System.out.println(a);
                String x = new String(bytes);
                System.out.println(x);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public void writeData(){
        try {
            PrintWriter p = new PrintWriter(new File("D://dow.txt"));
            p.println("如果我能回到从前");
            p.println("回到最原始的我");
            p.println("你是否会觉得我没有做错");
            p.flush();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void skd(){
        int x = 0;
        int count;
        try {
            FileInputStream fileInputStream = new FileInputStream(new File("D://dow.txt"));
            FileOutputStream fileOutputStream = new FileOutputStream(new File("D://RedSky/zw.txt"));
            Byte[] bytes = new Byte[1024];
            try {
                while ((count=fileInputStream.read()) != -1){
                    x += count;
                }
                System.out.println(x);
                fileOutputStream.write(x);
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    public void zhuiJia(){
        try {
            PrintWriter p = new PrintWriter(new FileWriter("D://wo.txt"));
            p.println("这难道是真的吗？");
            p.flush();
            p.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        IoUtil ioUtil = new IoUtil();
        ioUtil.writeData();
//        ioUtil.zhuiJia();
        ioUtil.input();
    }
}

